package com.zjj.juc;

/**
 * @author zhoujunjie
 * @desc TODO
 * @date
 */
import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;

public class Test3 {
    public static void main(String[] args) {
        CyclicBarrier barrier = new CyclicBarrier(5, () -> {
            System.out.println("员工已到齐，会议开始");
        });
        for (int i = 1; i <= 5; i++) {
            final int employeeId = i;
            new Thread(() -> {
                try {
                    Thread.sleep((long) (Math.random() * 5000));
                    System.out.println("员工" + employeeId + "已到达会议室");
                    barrier.await();
                } catch (InterruptedException | BrokenBarrierException e) {
                    Thread.currentThread().interrupt();
                }
            }).start();
        }
    }
}
